package com.gd.iot.energy.controller.systemadmin;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.systemadmin.dto.SupplierSaveDTO;
import com.gd.iot.energy.pojo.systemadmin.vo.SupplierPageVO;
import com.gd.iot.energy.pojo.systemadmin.vo.SupplierVO;
import com.gd.iot.energy.service.systemadmin.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统管理-系统设置-供应商管理
 *
 * @Description:
 * @Author: zgyz
 * @Date: 2020/8/6 23:20
 */
@Api(value = "系统管理-系统设置-供应商管理",tags = "系统管理-系统设置-供应商管理")
@RestController
@RequestMapping("/admin/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @ApiOperation("获取供应商列表")
    @SystemLogRecordMonitor("获取供应商列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supplierName", value = "名称", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getList")
    public ResponseEntity<List<SupplierVO>> getList(@RequestParam(value = "supplierName",required = false)String supplierName) {
        List<SupplierVO> supplierVOS = supplierService.getSupplierVOs(supplierName);
        return new ResponseEntity<>(supplierVOS);
    }

    @ApiOperation("获取供应商分页列表")
    @SystemLogRecordMonitor("获取供应商分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supplierName", value = "名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "supplierContact", value = "名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "supplierAddress", value = "名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<SupplierPageVO>> getPageList(
            @RequestParam(value = "supplierName",required = false)String supplierName,
            @RequestParam(value = "supplierContact",required = false)String supplierContact,
            @RequestParam(value = "supplierAddress",required = false)String supplierAddress,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<SupplierPageVO> pageVO = supplierService.getPageSupplierVOs(supplierName,supplierContact,supplierAddress,
                pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("获取供应商")
    @SystemLogRecordMonitor("获取供应商")
    @PostMapping("/get")
    public ResponseEntity<SupplierSaveDTO> get(Integer id){
        SupplierSaveDTO supplierSaveDTO = supplierService.getSupplier(id);
        return new ResponseEntity<>(supplierSaveDTO);
    }

    @ApiOperation("新增供应商")
    @SystemLogRecordMonitor("新增供应商")
    @PostMapping("/add")
    public ResponseEntity<Long> add(@RequestBody SupplierSaveDTO supplierSaveDTO){
        Long id = supplierService.add(supplierSaveDTO);
        return new ResponseEntity<>(id);
    }

    @ApiOperation("更新供应商")
    @SystemLogRecordMonitor("更新供应商")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody SupplierSaveDTO supplierSaveDTO){
        boolean res = supplierService.update(supplierSaveDTO);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("删除供应商")
    @SystemLogRecordMonitor("删除供应商")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = supplierService.delete(ids);
        return new ResponseEntity<>(res);
    }
}
